package com.google.code.virtualhockey.vhx.server.servlet.rpc

import com.google.code.virtualhockey.vhx.shared.rpc.{IResponse, ICommand}

/**
 * Must be implemented by all concrete command handlers.
 *
 * @param A the type of the command to handle
 * @param B the type of the response of the handled command
 */
trait TCommandHandler[A <: ICommand[B], B <: IResponse] {
  /**
   * Handles the specified command.
   *
   * @param ctx the current execution context
   * @param cmd the command to be handled
   * @return a response to be sent back to the client
   * @throws WebServerException signals abonormal termination of the command handling
   */
  def handle ( ctx: CommandContext, cmd: A ): B

  /**
   * Returns the role that the currently connected user must have to be able to execute the command.
   */
  def requiredAuthRole: AuthRole.Value
}
